﻿
@{
    ViewBag.Title = "仓库新增修改";

}
<link rel="stylesheet" href="../../Customiz/layui/css/layui.css" media="all">

<form class="layui-form" action="" lay-filter="example">
    <div class="layui-form" lay-filter="layuiadmin-form-admin" id="layuiadmin-form-admin" style="padding: 20px 30px 0 0;">
        <div class="layui-form-item">
            <label class="layui-form-label">仓库名称</label>
            <div class="layui-input-inline">
                <input type="text" name="Warehouse_Name" id="Warehouse_Name" lay-verify="required" placeholder="请输入仓库名称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">管理员</label>
            <div class="layui-input-block">
                <select name="Warehouse_UserID" id="Warehouse_UserID" lay-filter="Warehouse_UserID">
                    <option value=""></option>
                </select>
            </div>
        </div>
        <div>
            <button class="layui-btn layui-btn-primary layui-btn-sm" id="Ord_Quxiao" style="float:right">取消</button>
            <button class="layui-btn layui-btn-normal layui-btn-sm" lay-submit lay-filter="Ord-Warehouse-Add-search" style="float:right;margin-right:20px">确定</button>
        </div>
    </div>
</form>
<script src="../../Customiz/scripts/jquery-3.4.1.min.js"></script>
<script src="../../Customiz/layui/layui.js"></script>
<script>

    $(function(){

    });


    layui.use(['table'], function () {
        var table = layui.table;
        var form = layui.form;
        var layer = layui.layer;



        $("#Ord_Quxiao").click(function () {
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引

            parent.layer.close(index); //再执行关闭
        });


        //表单验证
        form.verify({


        });

        //用户(巡查员id)
        $.ajax({
            url: '/User/GetUser',
            dataType: 'json',
            type: 'Post',
            async:false,
            data:{ name:"", dept:"", role:"5"},
            success: function (data) {
                $.each(data.data, function (index, item) {
                    $('#Warehouse_UserID').append(new Option(item.User_Name, item.User_ID)); // 下拉菜单里添加元素
                });
                layui.form.render("select");
                //重新渲染 固定写法
            }
        })
        if(@ViewBag.Type==2)
        {
            var select = 'dd[lay-value=' + @ViewBag.Warehouse_UserID + ']';
            $('#Warehouse_UserID').siblings("div.layui-form-select").find('dl').find(select).click();

            $("#Warehouse_Name").val('@ViewBag.Warehouse_Name');
        }
        //监听提交
        form.on('submit(Ord-Warehouse-Add-search)', function (data) {
            var field = data.field;
            //提交 Ajax 成功后，静态更新表格中的数据
            if(@ViewBag.Type==1)
            {
                $.ajax({
                    cache: false,
                    type: "Post",
                    async: false,
                    url: '/Record/AddWarehouse', //模拟接口
                    data: {
                        Warehouse_Name: field.Warehouse_Name,
                        Warehouse_UserID: field.Warehouse_UserID
                    },
                    dataType: 'json',
                    success: function (data) {
                        if (data == true) {
                            parent.layer.msg("新增成功！", { icon: 1 });

                            //window.parent.$(".layui-laypage-btn").click();//刷新父窗体列表
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭




                        } else {
                            parent.layer.msg("新增失败！", { icon: 2 });
                        }
                    }
                })

            }else
            {
                $.ajax({
                    cache: false,
                    type: "Post",
                    async: false,
                    url: '/Record/updateWarehouse', //模拟接口
                    data: {
                        Warehouse_ID:"@ViewBag.ID",
                        Warehouse_Name: field.Warehouse_Name,
                        Warehouse_UserID: field.Warehouse_UserID
                    },
                    dataType: 'json',
                    success: function (data) {
                        if (data == true) {
                            parent.layer.msg("修改成功！", { icon: 1 });

                            //window.parent.$(".layui-laypage-btn").click();//刷新父窗体列表

                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                        } else {
                            parent.layer.msg("修改失败！", { icon: 2 });
                        }
                    }
                })
            }
        });
    });
</script>